import {
  getDishesPriceList,
  submitDishesPrice,
  deleteDishesPrice,
  submitEditDishesPrice,
  getAdList,
  submitAdversing,
  editAd,
  deleteAd
 } from "@/api/publicScreenInfo"
import { Message } from 'element-ui';
export default {
  namespaced: true, // 封闭
  state: {},
  mutations: {},
  getters: {},
  actions: {
    /**
     * 公示菜价
     */
    // 获取公示菜价数据
    async fetchDishesPriceData(context, payload) {
      let { perPage, page } = payload
      try {
        const { data } = await getDishesPriceList(perPage, page)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 提交添加菜价
    async fetchSubmitDishesPrice(context, payload) {
      let { productId, price } = payload
      try {
        const { data } = await submitDishesPrice(productId, price)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 删除菜品
    async fetchDeleteDishesPrice(context, payload) {
      let { id } = payload
      try {
        const { data } = await deleteDishesPrice(id)
        return data
      } catch (err) {
        console.log(err)
      }
    },

    // 提交修改菜价
    async fetchSubmitEditDishesPrice(context, payload) {
      // let { type,title,playTime,playUrl,describe,machineType,startDate,endDate} = payload
      try {
        const { data } = await submitEditDishesPrice(payload)
        return data
      } catch (err) {
        console.log(err)
      }
    },


    /**
     * 公示广告
     */
    // 获取公示广告数据
    async fetchAdData(context, payload) {
      let { searchName, status, adType, machineType, perPage, page } = payload
      try {
        const { data } = await getAdList(searchName, status, adType, machineType, perPage, page)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 提交新增广告
    async submitAdversing(context, payload) {
      let { type, title, playTime, playUrl, describe, machineType, startDate, endDate } = payload
      try {
        const { data } = await submitAdversing(type, title, playTime, playUrl, describe, machineType, startDate, endDate)
        return data
      } catch (err) {
        console.log(err)
      }
    },
    // 停用广告
    async editAd(context, payload) {
      let { id } = payload
      try {
        const { data } = await editAd(id)
        return data
      } catch (err) {
        console.log(err)
        Message.error({
          type: 'error',
          message: '暂无该广告'
        })
      }
    },
    // 删除广告
    async deleteAd(context, payload) {
      let { id } = payload
      try {
        const { data } = await deleteAd(id)
        return data
      } catch (err) {
        console.log(err)
        Message.error({
          type: 'error',
          message: '删除失败'
        })
      }
    }
  }
}
